/*
Macros:
CUBE = 0, 1
*/
texture g_Texture;
float4 g_ComponentMask;

sampler TextureSampler = sampler_state {
	Texture = (g_Texture);
	AddressU = CLAMP;
	AddressV = CLAMP;
	AddressW = CLAMP;
	MinFilter = POINT;
	MagFilter = POINT;
	MipFilter = POINT;
};

struct VERTEX
{
	#if CUBE != 0
		float3 Tex : TEXCOORD0;
	#else
		float2 Tex : TEXCOORD0;
	#endif
};

float4 SampleTexture(VERTEX In)
{
	#if CUBE != 0
		return texCUBE(TextureSampler, In.Tex);
	#else
		return tex2D(TextureSampler, In.Tex);
	#endif
}

void AllPS(
	in VERTEX In,
	out float4 Out : COLOR0)
{
	Out = SampleTexture(In);
}

void AlphaPS(
	in VERTEX In,
	out float4 Out : COLOR0)
{
	Out.rgb = SampleTexture(In).a;
	Out.a = 1;
}

void SingleChannelPS(
	in VERTEX In,
	out float4 Out : COLOR0)
{
	float4 TextureSample = SampleTexture(In);
	Out.rgb = dot(TextureSample.rgb, g_ComponentMask.rgb);
	Out.a = TextureSample.a;
}

void ComponentMaskPS(
	in VERTEX In,
	out float4 Out : COLOR0)
{
	float4 TextureSample = SampleTexture(In);
	Out.rgb = TextureSample.rgb * g_ComponentMask.rgb;
	Out.a = TextureSample.a;
}

technique All           { pass { PixelShader = compile ps_3_0 AllPS(); } }
technique Alpha         { pass { PixelShader = compile ps_3_0 AlphaPS(); } }
technique SingleChannel { pass { PixelShader = compile ps_3_0 SingleChannelPS(); } }
technique ComponentMask { pass { PixelShader = compile ps_3_0 ComponentMaskPS(); } }

